//
//  ViewController.m
//  图片水印
//
//  Created by hyl on 16/6/26.
//  Copyright © 2016年 hyl. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //加载图片
    UIImage *image=[UIImage imageNamed:@"小黄人"];
    //创建上下文，之后与drawRect一样的操作
    //opaque:不透明度，不透明 Yes
    //scale:取值为0不缩放
    UIGraphicsBeginImageContextWithOptions(image.size, NO, 0);
    
    //开启上下文画上图片
    [image drawAtPoint:CGPointZero];
    
    //再添加文字
    NSString *str=@"HYL";
    NSMutableDictionary *textDic=[NSMutableDictionary dictionary];
    textDic[NSFontAttributeName]=[UIFont systemFontOfSize:30];
    textDic[NSForegroundColorAttributeName]=[UIColor redColor];
    textDic[NSStrokeWidthAttributeName]=@3;
    //// UIColor, default nil: same as foreground color
    textDic[NSStrokeColorAttributeName]=[UIColor blueColor];
    NSShadow *shade=[[NSShadow alloc]init];
    shade.shadowBlurRadius=1;
    shade.shadowColor=[UIColor redColor];
    shade.shadowOffset=CGSizeMake(2, 2);
    textDic[NSShadowAttributeName]=shade;
    //添加文字
    [str drawAtPoint:CGPointMake(70, 340) withAttributes:textDic];
    
    //从图片上下文里获得已经水印的图片
    UIImage *image1=UIGraphicsGetImageFromCurrentImageContext();
    //显示一下
    self.imageView.image=image1;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
